/*
 * NewLineAction.java
 * 
 * Created by demory on Mar 31, 2009, 7:47:22 AM
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.fpdev.apps.cart.actions;

import java.awt.Color;
import org.fpdev.apps.cart.Cartographer;
import org.fpdev.apps.cart.Editor;
import org.fpdev.apps.cart.network.Line;

/**
 *
 * @author demory
 */
public class CreateLineAction extends EditorBasedAction {

  private Line line_;

  private int id_;
  private String name_;

  public CreateLineAction(Editor ed, String name) {
    super(ed);
    id_ = 0;
    name_ = name;
  }

  public boolean doAction(Cartographer cart) {
    if(id_ == 0) id_ = ed_.getDocument().getNetwork().newLineID();
    line_ = new Line(id_, name_); //, Color.black, 10, 0);
    ed_.getDocument().getNetwork().addLine(line_);
    cart.getGUI().getControlFrameManager().getLinesFrame().addLine(line_);
    return true;
  }

  public boolean undoAction(Cartographer cart) {
    if(line_ == null) return false;

    ed_.getDocument().getNetwork().deleteLine(line_);
    cart.getGUI().getControlFrameManager().getLinesFrame().removeLine(line_);
    return true;
  }

  public String getName() {
    return "New Line";
  }

}
